#--------------求行、列标准形-------------
import numpy as np
import sympy
from sympy import Matrix
from sympy.matrices import dense
from sympy import *
import math

# a = [[1,0,1,0], [0,1,1,-1]]
a=np.array([[0,-2,6,-6,-10],[1,1,-3,1,-1],[0,1,-3,4,-7]])
# a = [[1,3,2,1,4],[2,6,1,0,7],[3,9,3,1,11]]
# a = [[1, 4, -1, 5, 6],
#      [2, 0, 0, 0, -14],
#      [-1, 2, -4, 0, 1],
#      [2, 6, -5, 5, -7]]
# Matrix convert to array
A_mat = Matrix(a)
A_arr1 = np.array(A_mat.tolist())
A_rref = np.array(A_mat.rref()[0].tolist())  # 最简行阶梯矩阵

r = np.linalg.matrix_rank(a)  # 求秩

count = 0
k = []  # 被选中的列向量
for i in range(A_rref.shape[0]):
    for j in range(A_rref.shape[1]):
        # 遇到1就说明找到了A矩阵的列向量的下标，这些下标的列向量组成B矩阵，然后再找下一行
        if A_rref[i][j] == 1:
            count += 1
            k.append(j)
            break

B = A_arr1[:, k]
C = A_rref[:r]  # 秩就是C矩阵的行数
B = Matrix(B)
print("列标准形B:",B)#参考
C = Matrix(C)
print("行标准形C:",C)
#--------------求行、列标准形-------------